﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Linq.Expressions;

namespace Test.Expressions
{
	

	public class ColumnExpression : DbExpression
	{
		
		
		public ColumnExpression(FieldInfo field)
			: base(nodeType: DbExpressionType.Column, type: field.FieldType) {
				this.field = field;	
			
		}
		public Type DeclaringType {
			get {
				return this.field.DeclaringType;
			}
		}
		public FieldInfo field { get; set; }
		/// <summary>
		/// Not every column projection will have an associated LambdaExpression, but
		/// we always need to have some alias for its associated subquery, 
		/// which is why a generic string property is used, and not a LambdaExpression.
		/// </summary>
		public string OwnerAlias { get; set; }
		public string Alias { get; set; }
		public string Name { get; set; }
			
		public MethodInfo Function { get; set; }

		public override int GetHashCode() {
			return this.Name.GetHashCode() + this.DeclaringType.GetHashCode();
		}

		
	}

	public class NComparer<T> : System.Collections.Generic.Comparer<T>
	{

		Comparison<T> comparison;
		public NComparer(Comparison<T> comparison) {
			this.comparison = comparison;
		}

		public override int Compare(T x, T y) {
			return this.comparison(x, y);
		}
	}

	
}
